<template>
    <div class="home_container">
        <el-container class="el_container">
            <el-header>
                <div class="left_container">
                    <img class="img_container" src='../assets/logos.jpg'>
                    <span class="span_container">给自己的歌</span>
                </div>
                <el-button type="info" @click="logout">退出</el-button>
            </el-header>
            <el-container>
                <el-aside :width="isCollapse ? '64px' : '200px'">
                    <div class="toggle-button" @click="toggleCollapse">|||</div>
                       <el-menu :collapse="isCollapse"
                                background-color="#333744"
                                text-color="#fff"
                                active-text-color="#ffd04b"
                                unique-opened
                                :collapse-transition="false"
                                router
                                default-active="/users"
                       >
                           <el-submenu index="1">
                           <template slot="title">
                               <i class="el-icon-location"></i>
                               <span>用户管理</span>
                           </template>
                           <el-menu-item index="/users">
                               <template slot="title">
                                   <i class="el-icon-menu"></i>
                                   <span>用户列表</span>
                               </template>
                           </el-menu-item>
                       </el-submenu>
                           <el-submenu index="2">
                               <template slot="title">
                                   <i class="el-icon-location"></i>
                                   <span>权限管理</span>
                               </template>

                               <el-menu-item index="/roles">
                                   <template slot="title">
                                       <i class="el-icon-location"></i>
                                       <span>角色列表</span>
                                   </template>
                               </el-menu-item>

                               <el-menu-item index="/rights">
                               <template slot="title">
                                   <i class="el-icon-location"></i>
                                   <span>权限列表</span>
                               </template>
                           </el-menu-item>
                           </el-submenu>
                           <el-submenu index="3">
                               <template slot="title">
                                   <i class="el-icon-location"></i>
                                   <span>商品管理</span>
                               </template>

                               <el-menu-item index="/categories">
                                   <template slot="title">
                                       <i class="el-icon-location"></i>
                                       <span>商品分类</span>
                                   </template>
                               </el-menu-item>
                               <el-menu-item index="1-1">
                                   <template slot="title">
                                       <i class="el-icon-location"></i>
                                       <span>分类参数</span>
                                   </template>
                               </el-menu-item>
                               <el-menu-item index="1-1">
                                   <template slot="title">
                                       <i class="el-icon-location"></i>
                                       <span>商品列表</span>
                                   </template>
                               </el-menu-item>
                           </el-submenu>
                           <el-submenu index="4">
                               <template slot="title">
                                   <i class="el-icon-location"></i>
                                   <span>订单管理</span>
                               </template>

                               <el-menu-item index="1-1">
                                   <template slot="title">
                                       <i class="el-icon-location"></i>
                                       <span>导航</span>
                                   </template>
                               </el-menu-item>
                           </el-submenu>
                           <el-submenu index="5">
                               <template slot="title">
                                   <i class="el-icon-location"></i>
                                   <span>数据统计</span>
                               </template>

                               <el-menu-item index="1-1">
                                   <template slot="title">
                                       <i class="el-icon-location"></i>
                                       <span>导航</span>
                                   </template>
                               </el-menu-item>
                           </el-submenu>
                       </el-menu>
                </el-aside>
                <el-main>
                    <router-view></router-view>
                </el-main>
            </el-container>
        </el-container>
    </div>
</template>

<script>
    import {getMenu} from "../api/user";

    export default {
        name: "Home",
        data() {
            return {
                isCollapse: false

            }
        },
        created() {
              this.getMenus()
        },
        methods: {
            // 折叠or展开
            toggleCollapse() {
                this.isCollapse = !this.isCollapse
            },
            // 退出
            logout() {
                window.sessionStorage.clear()
                this.$router.push('/login')
            },
            getMenus() {
                getMenu().then(res => {
                })
            }
        }
    }
</script>

<style scoped>
    .toggle-button {
        background-color: #4a5064;
        font-size: 10px;
        line-height: 24px;
        color: #fff;
        text-align: center;
        letter-spacing: 0.2em;
        cursor: pointer;
    }
    .el_container {
        height: 100%;
    }
    .home_container {
        height: 100%;
    }

    .el-header {
       background-color: #373d41;
        display: flex;
        justify-content: space-between;
        padding-left: 0;
        align-items: center;
        color: #fff;
        font-size: 20px;
    }

    .left_container {
        display: flex;
        align-items: center;
    }
    .span_container {
        margin-left: 15px;
    }

    .img_container {
        height: 50px;
        width: 50px;
        border-radius: 50%;
    }

    .el-aside {
        background-color: #333744;
    }

    .el-main{
        background-color: #eaedf1;
    }

</style>
